﻿using System;
using Autodesk.Revit.DB;
using YJKCoordinate;

namespace SetPipe.Utiltiy
{
	public class TwoPipeInputDataPakcer : InputDataPackerBase
	{
		internal TwoPipeInputDataPakcer(OnePipeInputDataPacker inputStart, OnePipeInputDataPacker inputEnd)
		{
			this.lstPipeInputParameter.Clear();
			this.lstPipeInputParameter.Add(inputStart.GetPipeParameters(0));
			this.lstPipeInputParameter.Add(inputEnd.GetPipeParameters(0));
			this.cornerKind = inputEnd.CornerKinde;
			this.setPoints(inputStart.GetPoint(0), inputEnd.GetPoint(0));
			this.useFamilyFileIndexs.Clear();
			this.useFamilyFileIndexs.Add(inputEnd.GetFamilyFileIndex(0));
		}

		internal Line GetLine(int val)
		{
			if (val == 0)
			{
				return this.offestLinePostive;
			}
			if (1 == val)
			{
				return this.offestLineNegtive;
			}
			return this.midLine;
		}

		internal XYZ GetDriection()
		{
			return this.driection;
		}

		private void setPoints(XYZ startPoint, XYZ endPoint)
		{
			this.lstPoints.Clear();
			this.lstPoints.Add(startPoint);
			this.lstPoints.Add(endPoint);
			if (startPoint.IsAlmostEqualTo(endPoint))
			{
				throw new CornerMakerException(StaticRescource.StrError_PointsNear);
			}
			this.driection = this.lstPoints[1].Add(-this.lstPoints[0]).Normalize();
			this.midLine = Line.CreateBound(this.lstPoints[0], this.lstPoints[1]);
			this.offestLinePostive = (this.midLine.CreateSameOffset(base.GetPipeParameters(1)[PipeUseParameterEnum.Width] / 2.0, StaticRescource.GetXYPlaneNorme(0)) as Line);
			this.offestLineNegtive = (this.midLine.CreateSameOffset(base.GetPipeParameters(1)[PipeUseParameterEnum.Width] / 2.0, StaticRescource.GetXYPlaneNorme(1)) as Line);
		}

		private XYZ driection;

		private Line midLine;

		private Line offestLinePostive;

		private Line offestLineNegtive;
	}
}
